# 定义棋盘大小
BOARD_ROWS = 10
BOARD_COLS = 9

# 初始化棋盘
def init_board():
    board = [[' ' for _ in range(BOARD_COLS)] for _ in range(BOARD_ROWS)]
    # 红方棋子
    board[0] = ['车', '马', '相', '仕', '帅', '仕', '相', '马', '车']
    board[2][1] = '炮'
    board[2][7] = '炮'
    for i in range(0, 9, 2):
        board[3][i] = '兵'

    # 黑方棋子
    board[9] = ['車', '馬', '象', '士', '将', '士', '象', '馬', '車']
    board[7][1] = '砲'
    board[7][7] = '砲'
    for i in range(0, 9, 2):
        board[6][i] = '卒'

    return board

# 打印棋盘
def print_board(board):
    print('  ', end='')
    for i in range(BOARD_COLS):
        print(i, end=' ')
    print()
    for i in range(BOARD_ROWS):
        print(i, end=' ')
        for j in range(BOARD_COLS):
            print(board[i][j], end=' ')
        print()

# 检查移动是否合法（简单版本）
def is_valid_move(board, from_row, from_col, to_row, to_col):
    piece = board[from_row][from_col]
    target = board[to_row][to_col]
    if piece == ' ':
        return False
    # 简单规则：不能吃自己的棋子
    if piece in '车马相仕帅炮兵' and target in '车马相仕帅炮兵':
        return False
    if piece in '車馬象士将砲卒' and target in '車馬象士将砲卒':
        return False
    return True

# 移动棋子
def move_piece(board, from_row, from_col, to_row, to_col):
    if is_valid_move(board, from_row, from_col, to_row, to_col):
        board[to_row][to_col] = board[from_row][from_col]
        board[from_row][from_col] = ' '
        return True
    return False

# 主游戏循环
def main():
    board = init_board()
    current_player = '红方'
    while True:
        print_board(board)
        print(f"{current_player} 回合")
        try:
            from_row, from_col = map(int, input("请输入要移动的棋子的行和列（用空格分隔）: ").split())
            to_row, to_col = map(int, input("请输入要移动到的行和列（用空格分隔）: ").split())
            if move_piece(board, from_row, from_col, to_row, to_col):
                if current_player == '红方':
                    current_player = '黑方'
                else:
                    current_player = '红方'
            else:
                print("无效的移动，请重新输入。")
        except ValueError:
            print("输入格式错误，请输入两个整数并用空格分隔。")

if __name__ == "__main__":
    main()